<?php
namespace app\zbj\controller;

use think\Db;
use think\Request;

class Transaction extends Base{

    // 查看交易记录
    public function showlist(Request $request)
    {
        $get=myarr($request->get());
        $get['p']=isset($get['p'])?$get['p']:config('paginate.list_rows');
        $get['kp']=isset($get['kp'])?$get['kp']:'';
        $get['mm']=isset($get['mm'])?$get['mm']:'';
        $get['hy']=isset($get['hy'])?$get['hy']:'';
        $get['zzh']=isset($get['zzh'])?$get['zzh']:'';
        $get['start']=isset($get['start'])?$get['start']:date('Y-m-d',strtotime('-1 day'));
        $get['end']=isset($get['end'])?$get['end']:date('Y-m-d');
        $get['agent']=isset($get['agent'])?$get['agent']:'';
        $jystart=str_replace('-','',$get['start']);
        $jyend=str_replace('-','',$get['end']);


        $where['refereecode']=['=','0'];
        if($get['agent']!=''){
            $where['agents']=['=',$get['agent']];
        }
        if($get['kp']!=''){
            $where['Kaiping']=['=',$get['kp']];
        }
        if($get['mm']!=''){
            $where['Business']=['=',$get['mm']];
        }
        if($get['hy']!=''){
            $where['Contract']=['=',$get['hy']];
        }
        if($get['zzh']!=''){
            $where['Subaccount']=['=',$get['zzh']];
        }
        if($get['start']!=''&&$get['end']!=''){
            $where['TradingDday']=['between',[$jystart,$jyend]];
        }
        $list=Db::name('transaction')->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->field('a.*')
            ->where($where)
            ->order('id desc')
//            ->select();
            ->paginate($get['p'],false,['query'=>$get]);
        $lists = Db::name('users')->alias('a')
            ->join('lc_agents b','a.aid=b.id')
            ->field('b.id,b.name,count(a.id) c')
            ->where('a.refereecode',0)->group('a.aid')
            ->order('id desc')->select();
//        var_dump($list);
//        dump($lists);
        $page=$list->render();
        $list=$list->items();
        $count['Count']=Db::name('transaction')->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->where($where)
            ->sum('Count');
        $count['Poundage']=Db::name('transaction')->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->where($where)
            ->sum('Poundage');
        $Float=Db::name('transaction')->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->where($where)
            ->column('`Float`');
        $count['Float'] = 0;
        foreach ($Float as $v){
            $count['Float'] += $v;
        }
        $count['Brokerage']=Db::name('transaction')->alias('a')
            ->join('lc_users b','a.uid=b.id')
            ->where($where)
            ->sum('Brokerage');

        return view('transaction/showlist2',['list'=>$list,'lists'=>$lists,'page'=>$page,'get'=>$get,'count'=>$count]);

//        return view('transaction/showlist2',['get'=>$get,'list'=>$list,'page'=>$page,'count'=>$count]);

    }


    public function xq(Request $request){
        $id=$request->get('id');
        $list=Db::name('transaction')->find($id);
        return $list;
    }

























}
